<%@page import="com.glowdayz.glowmee.dao.ProductDAO"%>
<%@page import="com.glowdayz.common.MultipartBox.FileInfo"%>
<%@page import="com.glowdayz.common.MultipartBox"%>
<%@page import="com.glowdayz.common.DBHandler"%>
<%@page import="com.glowdayz.common.ApiHandler"%>
<%@page import="com.glowdayz.common.ApiHandler.XmlData"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/xml; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%
	DBHandler.getInstance().connect();
	ApiHandler web = new ApiHandler(request, out, "JSPglowmee");
	
	MultipartBox mbox = MultipartBox.getInstance();
	
	// 업로드는 이 한 줄로 끝~!!!
	FileInfo finfo = mbox.upload2(request);
	
	int idRegister = 0;
	String requestText;
	if (finfo == null) {
		idRegister = web.getInt("idRegister");
		requestText = web.getValue("requestText");
	} else {
		idRegister = mbox.getInt("idRegister");
		requestText = mbox.getValue("requestText");
	}
	
	int insert = ProductDAO.getInstance().addRequestProduct(idRegister, requestText, finfo);
	
	if (insert < 1) {
		DBHandler.getInstance().disconnect();
		web.result(null, "요청 등록에 실패하였습니다.");
		return;
	}
	
	DBHandler.getInstance().disconnect();
	
	ArrayList<XmlData> list = new ArrayList<XmlData>();
	web.result("SUCCESS", "제품요청이 정상적으로 등록되었습니다.", list);
%>